#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
int x, y, n;
int cnt1, cnt2;
struct node1
{
	int a, b;
}S1[N];
struct node2
{
	int a, b;
}S2[N];
struct node
{
	char op;
	int a, b;
}S[N];
int cmp(node a, node b)
{
	if (a.a != b.a)return a.a < b.a;
	else return a.b > b.b;
}
int cmp1(node1 a, node1 b)
{
	if (a.a != b.a)return a.a < b.a;
	else return a.b > b.b;
}
int cmp2(node2 a, node2 b)
{
	if (a.a != b.a)return a.a < b.a;
	else return a.b > b.b;
}
int main()
{
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++) {
		string op;
		int v1, v2;
		cin >> op >> v1 >> v2;
		/*if (op[0] == 'A') {
			S1[++cnt1] = { v1,v2 };
		}
		else {
			S2[++cnt2] = { v1,v2 };
		}*/
		S[i] = { op[0],v1,v2};
	}
	if (n < y + x || cnt2 < y) {
		cout << -1 << endl;
		return 0;
	}
	//sort(S1 + 1, S1 + cnt1 + 1, cmp1);
	//sort(S2 + 1, S2 + cnt2 + 1, cmp2);
	sort(S + 1, S + n + 1, cmp);
	LL ans = 0;
	int cnt = 0;
	for (int i = 1; i <= x; i++) {
		//if (S[i].op == 'A')cnt++;
		ans += S[i].b;
	}
	for (int i = x + 1; i <= x + y; i++) {
		if (S[i].op == 'B') {
			ans += S[i].b;
		}
	}
	/*for (int i = 1; i <= x; i++) {
		ans += S1[i].b;
	}
	for (int i = 1; i <= y; i++) {
		ans += S2[i].b;
	}
	if (cnt1 < x) {
		for (int i = y + 1; i <= y + x - cnt1; i++) {
			ans += S2[i].b;
		}
	}*/
	cout << ans << endl;
	return 0;
}